<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>鼓励金兑现</title>
		<link rel="stylesheet" href="__AGENT__/css/css.css" />
		<script type="text/javascript" src="__PUBLIC__/static/js/jquery.min.js"></script>
		<link rel="stylesheet" href="__PUBLIC__/static/layui/css/layui.css">
		<script src="__PUBLIC__/static/layui/layui.js"></script>
	</head>

	<body>
		<form class="layui-form update_form" action="">
			<div class="layui-form-item">
				<label class="layui-form-label">鼓励金</label>
				<div class="layui-input-block update_shurk">
					<input type="text" value="{$oem_info['score']}" placeholder="23423元,（提现到余额扣除5%服务费）" class="layui-input" disabled="disabled">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">转账对象</label>
				<div class="layui-input-block update_shurk">
					<select name="type" id="type" lay-verify="required">
						{if $level==1}<option value="1">省代理</option>{/if}
						{if $level==1||$level==2}<option value="2">市代理</option>{/if}
						<option value="3">商家</option>
						<option value="4">会员</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">收款人手机号码 </label>
				<div class="layui-input-block update_shurk">
					<input type="text" onkeyup="clearNoNum(this)" id='mobile'  name="mobile" required lay-verify="required" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">转账金额</label>
				<div class="layui-input-block update_shurk">
					<input type="text" onkeyup="clearNoNum(this)" id='score'  name="score" required lay-verify="required" placeholder="￥" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item update_btnbox">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit lay-filter="formDemo">提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</body>

</html>
<script>
	//只能数字和小数点
	function clearNoNum(obj) {
		obj.value = obj.value.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
		obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字而不是.
		obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的.
		obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
	}
	
	function to_money(){
		var score = "{$oem_info['score']}";
		var to_num = $('#score').val();
		
		if(to_num < 10){
			layer.msg('转账金额不能小于10！');
			return ;
		}
		
		if(to_num > parseFloat(score)){
			layer.msg('鼓励金不足！');
			return ;
		}
		var phone = $("#mobile").val();
		var reg = /^1[3|4|5|6|7|8|9][0-9]{9}$/; //验证规则
		if(!reg.test(phone)) {
			layer.msg('手机号码格式不正确');
			onoff = true;
			return;
		}
		$.ajax({
             	type:"post",
                url:"{:url('oem/index/glj_zz')}",
                data: {
                	type	:$("#type").val(),
                	mobile	:phone,
                	score	: to_num
                },
                success:function(data){
                   layer.msg(data.msg, {
						  time: 1500 //2秒关闭（如果不配置，默认是3秒）
						}, function(){
							parent.location.reload();
						});
                },error:function(data){
                	var a = data;
                }
        });
	}
	
	//Demo
	layui.use('form', function() {
		var form = layui.form;

		//监听提交
		form.on('submit(formDemo)', function(data) {
			//layer.msg(JSON.stringify(data.field));
			to_money();
			return false;
		});
	});
</script>